<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib  prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="redis" uri="http://www.shopjsp.com/redisTag/functions" %>
<c:set var="srcPath" value="${redis:getSysConfig('sysFileVisitRoot_back')}"/>
<c:set var="basePath" value="${redis:getSysConfig('base_path_back')}"/>
<script type="text/javascript">
	function showProductParameterByProductTypeId(productTypeId){
        $.ajax({
            type: "POST",
            dataType: "JSON",
            async:false,
            url: "${basePath}/back/shopProduct/getProductParameterAndValueList.sjson",
            data: {productTypeId:productTypeId},
            success: function(data){
                var productParameterList = data.productParameterList;
                if (productParameterList != "" && productParameterList != null) {
                    $("#totalProdParamTable").empty();
                    var htmlParamStr = "";
                    var paramValue_index=0;/**用于计算生成的参数值控件的下标，并将值传递到后台**/
					for (var i = 0; i < productParameterList.length; i++) {//参数组循环
                        var productParameterValueList = productParameterList[i].shopProductParameterValueList;
						if(productParameterValueList !='' && productParameterValueList != null) {
							htmlParamStr += "<table class='addOrEditTable table-bordered table' id='parameterTable" + i + "'  width='100%'>";
							htmlParamStr += "<tr><td class='tocenter_th' colspan='4'><strong>" + productParameterList[i].paramName + "</strong>" +
								"<input type='hidden' name='paramGroupList[" + i + "].name' value='" + productParameterList[i].paramName + "'/>" +
								"<input type='hidden' name='paramGroupList[" + i + "].paramGroupId' value='" + productParameterList[i].paramId + "'/>"+
								"<input type='hidden' name='paramGroupList[" + i + "].order' value='" + productParameterList[i].sort + "'/>";
							htmlParamStr += "</tr>";
                            var isValidCount=1;/**有效可显示的规格参数个数计数器，用于换行计算**/
							for (var j = 0; j < productParameterValueList.length; j++) {//参数循环
                                if(isValidCount%2==1){/**表示第2个还是换行，一行2个**/
                                	htmlParamStr += "<tr>";
                                }
								htmlParamStr += "<th style='text-align: right;width: 200px;' class='toright_td'> " + productParameterValueList[j].paramValueName + "：</th>" +
									"<input type='hidden' name='paramGroupInfoList[" + paramValue_index + "].name' value='" + productParameterValueList[j].paramValueName + "'/> " +
									"<input type='hidden' name='paramGroupInfoList[" + paramValue_index + "].pgiId' value='" + productParameterList[i].paramId + "'/> "+
									"<input type='hidden' name='paramGroupInfoList[" + paramValue_index + "].order' value='" + productParameterValueList[j].sort + "'/>" +
									"<input type='hidden' name='paramGroupInfoList[" + paramValue_index + "].pgInfoId' value='" + productParameterValueList[j].paramValueId + "'/>";

								if(j==productParameterValueList.length-1 && isValidCount%2==1){/**判断最后一个是奇数还是偶数，是奇数进行样式处理**/
									htmlParamStr += "<td class='toleft_td' colspan='3'><div class='form-group'>" +
										"<input id='paramValue_"+productParameterValueList[j].paramValueId+"' class='form-control input-sm' type='text' name='paramGroupInfoList[" + paramValue_index + "].value' value=''/></div></td>";
                                }else{
                                    htmlParamStr += "<td class='toleft_td'><div class='form-group'>" +
                                        "<input id='paramValue_"+productParameterValueList[j].paramValueId+"' class='form-control input-sm normal' type='text' name='paramGroupInfoList[" + paramValue_index + "].value' value=''/></div></td>";
                                }
                                if(isValidCount%2==0){/**表示第2个还是换行，一行2个**/
                                	htmlParamStr += " </tr>";
                                }
                                isValidCount++;
                                paramValue_index++;
							}
							htmlParamStr += "</tr>";
							htmlParamStr += "</table>";
						}
					}
					$("#totalProdParamTable").append(htmlParamStr);

                } else {
                    $("#totalProdParamTable").html("<tr><td>该分类下无商品规格参数信息</td></tr>");
                }
            }
        });
	}

	function initProductParameterInfo(productTypeId,productParametersValue) {
        showProductParameterByProductTypeId(productTypeId);
        /**先初始化产品分类对应的参数及参数组信息**/
        var productParametersValueObj = JSON.parse(productParametersValue);
		for(var i=0;i<productParametersValueObj.length;i++){
            var paramGroupInfoList=productParametersValueObj[i].paramGroupInfo;
            for(var j=0;j<paramGroupInfoList.length;j++){
                var paramGroupInfo=paramGroupInfoList[j];
                $("#paramValue_"+paramGroupInfo.pgInfoId).val(paramGroupInfo.value);
			}
		}

	}
</script>


<div style="margin-top: 10px;">
	<table id="totalProdParamTable"  class="addOrEditTable table-bordered table" style="width:100%;">
		<tr id="noParamTr"><td>无商品规格参数信息，请检查“基本信息”标签中是否已选择商品分类</td></tr>
	</table>
</div>